local skel = fk.CreateSkill{
  name = "kqf__wanyi",
}

local KleeU = require "packages/klee_xy_I/utility/k_utility"

Fk:loadTranslationTable{
  ["kqf__wanyi"] = "婉嫕",
  [":kqf__wanyi"] = "当你需要使用基本牌时，你可以选择一名其他角色，然后其可以将你场上的"..
  "一张牌移动至其场上并令你视为使用该基本牌；若其未如此做，此技能本回合失效。",

  ["$kqf__wanyi1"] = "天性婉嫕，易以道御。",
  ["$kqf__wanyi2"] = "婉嫕利珍，为后攸行。",

  ["#kqf__wanyi"] = "婉嫕：你可以令一名其他角色将你场上的一张牌移动至其场上，<br>视为你使用一张基本牌；若其未如此做，此技能本回合失效。",
  ["#kqf__wanyi_ask"] = "令一名角色移动你场上的一张牌",
  ["#kqf__wanyi2_ask"] = "移动 %src 场上的一张牌至你场上，或令“婉嫕”本回合失效",

}

skel:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  prompt = "#kqf__wanyi",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local names = player:getViewAsCardNames(skel.name, all_names)
    if #names == 0 then return end
    return UI.CardNameBox {choices = names, all_names = all_names}
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = skel.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    local to = room:askToChoosePlayers(player,{
      targets = table.filter(room:getOtherPlayers(player),
        function (p)
          return #room:canMoveCardInBoard("e",{player},nil,{p}) +  #room:canMoveCardInBoard("j",{player},nil,{p}) > 0
        end),
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      cancelable = false,
      prompt = "#kqf__wanyi_ask",
    })[1]
    if not to then
      room:invalidateSkill(player, skel.name, "-turn", skel.name)
      return "false"
    end
    local yesno = KleeU.askYesOrNo(to, "#kqf__wanyi2_ask:"..player.id ,skel.name)
    if not yesno then
      room:invalidateSkill(player, skel.name, "-turn", skel.name)
      return "false"
    end
    local moveinfo = room:askToMoveCardInBoard(to, {
      target_one = player,
      target_two = to,
      skill_name = skel.name,
      move_from = player,
    })
    if not moveinfo then
      room:invalidateSkill(player, skel.name, "-turn", skel.name)
      return "false"
    end
  end,
  enabled_at_play = function (self, player)
    local to = player.next
    if #player:getCardIds("ej") < 1 then return false end
    while to ~= player do
      for _, id in ipairs(player:getCardIds({Player.Equip,Player.Judge})) do
        if Fk:getCardById(id).subcards ~= 0 and player:canMoveCardInBoardTo(to,id) then
          return true
        end
      end
      to = to.next
    end
    return false
  end,
  enabled_at_response = function(self, player, response)
    if response then return false end
    local to = player.next
    if #player:getCardIds("ej") < 1 then return false end
    while to ~= player do
      for _, id in ipairs(player:getCardIds({Player.Equip,Player.Judge})) do
        if Fk:getCardById(id).subcards ~= 0 and player:canMoveCardInBoardTo(to,id) then
          return true
        end
      end
      to = to.next
    end
    return false
  end,
})

return skel